import { getAreaObj, uploadType, regularRule } from '@/utils/util'

export const importConfig = {
	tabSteps: [
		{
			label: '下载模板',
			download: '下载模板',
			active: 1,
			versionNumber: 1,
			rules: [
				{
					label: '下载最新导入模板。共1个：',
					children: [
						{
							label: '《特殊老人服务表》',
							link: true,
							url: 'view_omSpecialServiceObject_downloadTemplate',
						},
					],
				},
			],
		},
		{
			label: '导入基础信息',
			description: '（可跳过）',
			uploadTip: '特殊老人服务信息表',
			active: 2,
			versionNumber: 1,
			url: 'view_omSpecialServiceObject_import',
			code: 4003,
		},
	],
}

export const formConfig = {
	inline: false,
	showBtn: true,
	labelPosition: 'top',
	labelWidth: '120px',
	column: [
		{
			label: '所属地区',
			prop: 'be_areas',
			propName: 'be_areas_name',
			type: 'AplidAreaSelect',
			span: 24,
			rules: [{ required: true, message: '请选择所属地区' }],
		},
		{
			label: '签约服务组织机构',
			prop: 'orgName',
			type: 'input',
			span: 12,
			rules: [{ required: true, message: '请输入签约服务组织机构' }],
		},
		{
			label: '姓名',
			prop: 'name',
			type: 'input',
			span: 12,
			rules: [{ required: true, message: '请输入姓名' }],
		},
		{
			label: '身份证号',
			prop: 'idCard',
			type: 'input',
			span: 12,
			rules: [{ required: true, message: '请输入身份证号' }],
		},
		{
			label: '类型',
			prop: 'specialCategory',
			propName: 'specialCategoryLabel',
			type: 'remoteSelect',
			code: 'OM_SPECIAL_CATEGORY',
			api: 'getDictItemList',
			filterKey: 'value',
			multiple: false,
			span: 12,
			rules: [{ required: true, message: '请选择类型' }],
		},
		{
			label: '签约日期',
			prop: 'startTimeBetween',
			type: 'datetimerange',
			span: 24,
			separator: '至',
			format: 'YYYY年MM月DD HH:mm:ss',
			valueFormat: 'YYYY-MM-DD HH:mm:ss',
			rules: [{ required: true, message: '请选择签约时间' }],
		},
	],
}

export const searchConfig = {
	inline: true,
	showBtn: true,
	labelPosition: 'left',
	column: [
		{
			label: '所属地区',
			prop: 'be_areas',
			type: 'AplidAreaSelect',
			span: 8,
		},
		{
			label: '组织机构',
			prop: 'orgName',
			type: 'input',
			span: 8,
		},
		{
			label: '姓名',
			prop: 'name',
			type: 'input',
			span: 8,
		},
		{
			label: '身份证号',
			prop: 'idCard',
			type: 'input',
			span: 8,
		},
		{
			label: '创建人',
			prop: 'createUserName',
			type: 'input',
			span: 8,
		},
		{
			label: '类型',
			prop: 'specialCategory',
			type: 'remoteSelect',
			code: 'OM_SPECIAL_CATEGORY',
			api: 'getDictItemList',
			span: 8,
		},
		{
			label: '创建时间',
			prop: 'createTimeBetween',
			type: 'dateBetween',
			valueFormat: 'YYYY-MM-DD HH:mm:ss',
			span: 8,
		},
		{
			label: '签约时间',
			prop: 'signTimeBetween',
			type: 'dateBetween',
			valueFormat: 'YYYY-MM-DD HH:mm:ss',
			span: 8,
		},
	],
}

export const tableConfig = {
	stripe: true,
	border: true,
	columns: [
		{ label: '所属区', prop: 'beAreaName' },
		{ label: '组织机构名称', prop: 'orgName' },
		{ label: '姓名', prop: 'name' },
		{ label: '身份证号', prop: 'idCard' },
		{ label: '类型', prop: 'specialCategoryLabel' },
		{ label: '签约开始时间', prop: 'startTime' },
		{ label: '签约结束时间', prop: 'endTime' },
		{ label: '创建人', prop: 'createUserName' },
		{ label: '创建时间', prop: 'createTime' },
		{
			label: '操作',
			prop: 'menu',
			width: 300,
			fixed: 'right',
		},
	],
}

export const api = {
	index: 'view_omSpecialServiceObject_page',
	add: 'view_omSpecialServiceObject_add',
	edit: 'view_omSpecialServiceObject_edit',
	delete: 'view_omSpecialServiceObject_del',
	import: 'view_omSpecialServiceObject_import',
	export: 'view_omSpecialServiceObject_export',
	detail: 'view_omSpecialServiceObject_view',
	mulitSet: 'mulitSet',
}
export const auth = {
	...api,
}
export const baseConfig = {
	pageName: '特殊老人服务',
	dictcodes: ['OM_SPECIAL_CATEGORY'],
	rowKey: 'id',
	addLabel: '新增',
	tipLabel: 'name',
	exportMqTopic: '/ning/export/',
	api,
	auth,
	menuBtn: [
		{
			icon: 'editor',
			label: '编辑',
			type: 'primary',
			operate: 'edit',
			auth: auth.edit,
			text: true,
			show: true,
		},
		{
			icon: 'delete',
			label: '删除',
			type: 'danger',
			operate: 'delete',
			auth: auth.delete,
			text: true,
			show: true,
		},
		{
			icon: 'detail',
			label: '详情',
			type: 'primary',
			operate: 'detail',
			auth: auth.index,
			text: true,
			show: true,
		},
	],
	operateFormate: async (form, type) => {
		return new Promise((resolve, reject) => {
			const beAreasObj = getAreaObj(form, 'be', 'set')
			form.startTimeBetween = [form.startTime, form.endTime].filter(Boolean)
			resolve({
				...form,
				be_areas: beAreasObj.areaIds,
				be_areas_name: beAreasObj.names,
			})
		})
	},
	saveFormate: async (form) => {
		return new Promise((resolve, reject) => {
			const beAreasObj = getAreaObj(form.be_areas, 'be')
			const beAreasNameObj = getAreaObj(form.be_areas_name, 'be')
			if (form.startTimeBetween && Array.isArray(form.startTimeBetween)) {
				const str = form.startTimeBetween
				form.startTime = str[0]
				form.endTime = str[1]
			}
			resolve({
				...form,
				...beAreasObj,
				...beAreasNameObj,
				be_areas: undefined,
				be_areas_name: undefined,
				startTimeBetween: undefined,
			})
		})
	},
	beforeOnLoadFormate: async (query) => {
		const beAreas = getAreaObj(query.be_areas, 'be')
		return new Promise((resolve, reject) => {
			resolve({
				...query,
				...beAreas,
				be_areas: undefined,
			})
		})
	},
	onLoadFormate: async (arr) => {
		return new Promise((resolve, reject) => {
			resolve(arr)
		})
	},
	dialogConfig: {
		width: '75%',
	},
	searchConfig,
	formConfig,
	tableConfig,
	importConfig,
	detailConfig: formConfig,
}
